package com.tfos.study.mvc.web.binding.initializer.controller;

import com.tfos.study.mvc.web.binding.initializer.entity.Organization;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 类功能说明：WebBindingInitializer处理请求参数的绑定控制器 <br/>
 * 公司名称：TF（腾飞）开源 <br/>
 * 作者：luorongxi <br/>
 */
@Slf4j
@RestController
public class TestWebBindingInitializerController {

    @PostMapping(value = "/webbindinginitializer")
    public String WebBindingInitializer(@Valid @RequestBody Organization org, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return bindingResult.getFieldError().getDefaultMessage();
        }
        log.info(org.toString());
        return org.toString();
    }
}
